<%-- 
    Document   : login_validate
    Created on : Apr 25, 2012, 7:55:17 PM
    Author     : Dell
--%>
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%@ page import="java.util.List"%>  
<%@ page import="java.util.Iterator"%>  
<%@ page import="org.apache.commons.fileupload.*"%>  
<%@ page import="org.apache.commons.fileupload.disk.*"%>  
<%@ page import="org.apache.commons.fileupload.servlet.*"%> 
<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>

<%
    String p = request.getParameter("p");
    String u = request.getParameter("u");
    
    String driver = "org.gjt.mm.mysql.Driver";
    Class.forName(driver).newInstance();

    Connection con=null;
    ResultSet rst=null;
    Statement stmt=null;

    try{
            String url="jdbc:mysql://localhost:3306/progin_171_13509008?user=root";
            con=DriverManager.getConnection(url);
            stmt=con.createStatement();
    }
    catch(Exception e){
            System.out.println(e.getMessage());
    }
    
    String query = "select * from user where user_name ='"+u+"' and password ='"+p+"'";
    rst = stmt.executeQuery(query);
    
    Integer sum = 0;
    while(rst.next())
               {
        sum++;
    }
    rst.first();
    
    if(sum == 0)
               {
        out.print(0);
    }
    else
               {
        session.setAttribute("user_name", u);
        session.setAttribute("login", "true");
        out.print(1);
    } 
    
%>

